package com.common.base;

import com.common.exception.UnloginException;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.common.constant.Codes;
import com.common.exception.CustomException;
import com.shiro.UserPrincipal;

/**
 * Controller公共组件
 *
 */
public abstract class BaseController {
	protected Logger logger = LoggerFactory.getLogger(getClass());

	protected UserPrincipal getUserPrincipal(){
		try {
			if(null==SecurityUtils.getSubject().getPrincipal()) {
				throw new UnloginException();
			}
			return (UserPrincipal) SecurityUtils.getSubject().getPrincipal();
		} catch (Exception e) {
			throw new UnloginException();
		}
	}

	protected Long getUserId(){
		try {
			return getUserPrincipal().getUserId();
		} catch (Exception e) {
			throw new UnloginException();
		}
	}
}
